import request from '@/utils/request';

import axios from 'axios';

// 班级API基础URL
const API_URL = '/api/staff/class';

export interface ClassData {
  id: number;
  grade: string;
  className: string;
  studentCount: number;
  headTeacherId?: number;
  createTime?: string;
  updateTime?: string;
}

export interface ClassQueryParams {
  grade?: string;
  className?: string;
  current: number;
  size: number;
}

export interface ApiResponse<T> {
  code: number;
  message: string;
  data: T;
}

export interface PageResult<T> {
  records: T[];
  total: number;
  size: number;
  current: number;
}

export function getClassList(params: ClassQueryParams) {
  return request.get<PageResult<ClassData>>('/api/staff/class/page', { params });
}

export function getClassById(id: number) {
  return request.get<ClassData>(`/api/staff/class/${id}`);
}

export function addClass(data: Omit<ClassData, 'id' | 'createTime' | 'updateTime'>) {
  return request.post<void>('/api/staff/class', data);
}

export function updateClass(data: ClassData) {
  return request.put<void>('/api/staff/class', data);
}

export function deleteClass(id: number) {
  return request.delete<void>(`/api/staff/class/${id}`);
}

export default {
  /**
   * 获取所有班级列表
   * @returns {Promise} - API响应
   */
  getClassList() {
    return axios.get(`${API_URL}/list`);
  }
}
